$(function () {
    init();
    city();
    fristLoad();
    search();
    checkAllClick();
    Dchoose();
});


// 选择地区的点击事件
var bool = true;
$("body").on("click", function () {
    $("#city_1").hide();
    bool = true;
})

$("body").on("click", ".left>div>button", function (event) {
    if (bool) {
        $("#city_1").show();
        bool = false;
    }else {
        $("#city_1").hide();
        bool  = true;

    }


    event.stopPropagation();
});
$("body").on("click", "#city_1", function (event) {
    $("#city_1").show();
    event.stopPropagation();
})
var changeCity = 1;
function fristLoad() {



//	通过查询城市获取项目列表

    $("#checkOut").click(function () {
        $("#table-fundManage1").bootstrapTable({
            url:"http://192.168.59.3:8082/console/usermanage/companylessee/CompanyInfoBy?companyType=1&pageNum=1&pageSize=10",
            contentType:"application/json",
            responseHandler: function (res) {
                console.log(res);
                return {rows: res.data.list, total: res.data.total};
            },
            onLoadSuccess: function (data) {
                console.log(data);
            }

        });
    });
}
function init() {
   $("#table-fundManage1").bootstrapTable({
        url:"http://192.168.59.3:8082/console/usermanage/companylessee/CompanyInfoBy",
        contentType:"application/json",
       onSuccessLoad:function (data) {
           console.log(data);
       },
        responseHandler: function (res) {
            console.log(res);
            return {rows: res.data.list, total: res.data.total};
        },

    })
    // $.ajax({
    //     type: "get",
    //     url: "http://192.168.59.3:8082/console/shopping/shop?shopType=2",
    //     contentType: "application/json",
    //     success: function (data) {
    //         console.log(data);
    //         var data1 = JSON.parse(data);
    //         $("#table-fundManage1").bootstrapTable({
    //             data: data1.data,
    //             onSuccessLoad: function (data) {
    //                 console.log(data);
    //
    //             }
    //         })
    //
    //     },
    //     error: function (err) {
    //         console.log(err);
    //     }
    // });
    $("#tab-first>li").eq(1).on("click", function () {
        changeCity = 2;
        $.ajax({
            type: "get",
            url: "http://192.168.59.3:8082/console/shopping/shop?shopType=2",
            contentType: "application/json",
            success: function (data) {
                console.log(data);
                var data1 = JSON.parse(data);
                $("#table-fundManage2").bootstrapTable({
                    data: data1.data,
                    onSuccessLoad: function (data) {
                        console.log(data);

                    }
                })

            },
            error: function (err) {
                console.log(err);
            }
        });

    });
    $("#tab-first>li").eq(2).on("click", function () {
        console.log(window.cityid);
        changeCity = 3;
        $.ajax({
            type: "get",
            url: "http://192.168.59.3:8082/console/shopping/shop?shopType=3",
            contentType: "application/json",
            success: function (data) {
                console.log(data);
                var data1 = JSON.parse(data);
           $("#table-fundManage3").bootstrapTable({
            data: data1.data,
            onSuccessLoad: function (data) {
            console.log(data);

                    }
                })

            },
            error: function (err) {
                console.log(err);
            }
        });

    });

}
function process(value,row,index) {
    console.log(row);
    return "<button class='shelves' onclick=''>强制下架</button><button class='details'>详情</button>"
}
function shelves() {
    
}
function responseHandler(response) {
    console.log(response.data);
    var needData = {
        rows: response.data.list,
        total: response.total
    };
    return needData;
}
// 获取所有的城市
function city() {
//	 获取所有的省份
    $.ajax({
        type: "get",
        url: "http://192.168.59.3:8082/console/basedata/area/provincelist",
        contentType: "application/json",
        success: function (data) {

            var data1 = JSON.parse(data).data;
            var sel1 = document.getElementsByClassName("prov")[0];
            var sel2 = document.querySelector(".city");

            for (var i = 0; i < data1.length; i++) {
                var optionObj = document.createElement('option');
                optionObj.innerHTML = data1[i].province;
                optionObj.value = data1[i].provinceid;
                sel1.appendChild(optionObj);
            }

            //          获取所有的市
            $.ajax({
                type: "get",
                url: "http://192.168.59.3:8082/console/basedata/area/citylist",
                contentType: "application/json",
                success: function (data) {

                    var data2 = JSON.parse(data).data;

                    sel1.onchange = function () {

                        for (var i = 0; i < sel2.children.length; i++) {

                            sel2.removeChild(sel2.children[i]);
                            i--;
                        }
                        for (var k = 0; k < data2.length; k++) {
                            if (sel1.value == data2[k].father) {
                                var optionObj = document.createElement('option');
                                optionObj.innerHTML = data2[k].city;
                                optionObj.value = data2[k].cityid;
                                sel2.appendChild(optionObj);
                            }

                        }


                    }
                    sel2.onchange = function () {

                        window.cityid = sel2.value;
                    if ( changeCity == 1 ){
                        $.ajax({
                            type: "get",
                            url: "http://192.168.59.3:8082/console/shopping/shop?shopType=1",
                            contentType: "application/json",
                            success: function (data) {
                                console.log(data);
                                var data1 = JSON.parse(data);
                                $("#inpCheckOut").val(data1.data[0].shopName);


                            },
                            error: function (err) {
                                console.log(err);
                            }
                        });


                    }else if (changeCity == 2){
                        $.ajax({
                            type: "get",
                            url: "http://192.168.59.3:8082/console/shopping/shop?shopType=3",
                            contentType: "application/json",
                            success: function (data) {
                                console.log(data);
                                var data1 = JSON.parse(data);
                                $("#table-fundManage3").bootstrapTable({
                                    data: data1.data,
                                    onSuccessLoad: function (data) {
                                        console.log(data);

                                    }
                                })

                            },
                            error: function (err) {
                                console.log(err);
                            }
                        });
                    }else{
}
 }
},
                error: function (err) {
                    console.log(err);
                }
            });

        },
        error: function (err) {
            console.log(err);
        }
    });

}
  // 按条件搜索输入框中的内容
function search () {
    $("#searchOption1").click(function () {
    $("#table-fundManage1").bootstrapTable("refresh");
    });
     $("#clearOption1").click(function () {
         for (var i =0; i< 3;i++) {
             $(".order-num>input").eq(i).val("");
         }
         $("#table-fundManage1").bootstrapTable("refresh");

     });



  }


function checkAllClick() {
    $("#table-fundManage1 [name=btSelectAll]").click();
}

function checkAll1Click() {
    $("#qhTable_2 [name=btSelectAll]").click();
}

function Dchoose() {
    console.log("1");
    $("#table-fundManage1 [name=btSelectItem]").change(function () {
        if ($("#table-fundManage1 [name=btSelectItem]").length == $("#table-fundManage1 [name=btSelectItem]:checked").length) {
            $(".checkBox1").prop("checked", true);
            }
            else {
            $(".checkBox1").prop("checked", false);
        }
    });
}

function Dchoose1() {
    $("#qhTable_2 [name=btSelectItem]").change(function () {
        if ($("#qhTable_2 [name=btSelectItem]").length == $("#qhTable_2 [name=btSelectItem]:checked").length) {
            $(".Dchoose1").prop("checked", true);
        } else {
            $(".Dchoose1").prop("checked", false);
        }
    })
}


